<?php

/**
 * Creater : nghiat
 * Date : 19/10/2010
 * Idea : Class Xu ly thong thong doi tuong danh muc
 */
class listxml_ListController extends Zend_Controller_Action {
    public function auth(){
        $url = Efy_Init_Config::_getCurrentHttpAndHost();
        if ($_SESSION['STAFF_PERMISSTION'] != 'ADMIN_SYSTEM'){
            $url = $url .'public/error/index/';
            $this->_redirect($url);
        }
    }
    //Phuong thuc init()
    public function init() {
        //Check quyền NSD
        $this->auth();
        Zend_Loader::loadClass('Zend_Json');
        Zend_Loader::loadClass('Listxml_modList');
        Zend_Loader::loadClass('Efy_Init_Config');
        //Load cau hinh thu muc trong file config.ini
        $tempDirApp = Zend_Registry::get('conDirApp');
        $this->_dirApp = $tempDirApp->toArray();
        $this->view->dirApp = $tempDirApp->toArray();
        //Lay duong dan thu muc goc (path directory root)
        $this->view->baseUrl = $this->_request->getBaseUrl() . "/public/";
        if (!$this->_request->isXmlHttpRequest()) {
            //Cau hinh cho Zend_layout
            Zend_Layout::startMvc(array(
                'layoutPath' => $this->_dirApp['layout'],
                'layout' => 'index'
            ));
            //Load ca thanh phan cau vao trang layout (index.phtml)
            $response = $this->getResponse();

            //Load cau hinh thu muc trong file config.ini de lay ca hang so dung chung
            $tempConstPublic = Zend_Registry::get('ConstPublic');
            $this->_ConstPublic = $tempConstPublic->toArray();
            //Lay so dong tren man hinh danh sach
            $this->view->NumberRowOnPage = $this->_ConstPublic['NumberRowOnPage'];
            //Duong dan file JS xu ly modul		
            $objConfig = new Efy_Init_Config();
            $this->view->JSPublicConst = $objConfig->_setJavaScriptPublicVariable();
            $this->view->UrlAjax = $objConfig->_setUrlAjax();
            //Tao doi tuong XML
            Zend_Loader::loadClass('Efy_Publib_Xml');
            // Load tat ca cac file Js va Css
            $this->view->LoadAllFileJsCss = Efy_Publib_Library::_getAllFileJavaScriptCss('', 'efy-js', 'list/jsList.js,list/jquery.uploadify.v2.1.4.min.js,list/swfobject.js,jQuery.equalHeights.js,chosen/chosen.jquery.js,list/list.js,efyxml.js', ',', 'js') . Efy_Publib_Library::_getAllFileJavaScriptCss('public/efy-js/List', '', '', '', 'css') .
                    Efy_Publib_Library::_getAllFileJavaScriptCss('', 'efy-style', 'chosen/chosen.css', ',', 'css');
            //Dinh nghia current modul code
            $this->view->currentModulCode = "ADMIN";
            $this->view->currentModulCodeForLeft = "list";
            //Hien thi file template
            $response->insert('header', $this->view->renderLayout('header.phtml', './application/views/scripts/'));     //Hien thi header 
            $response->insert('menu', $this->view->renderLayout('menu.phtml', './application/views/scripts/'));      //Hien thi header 		    
            $response->insert('footer', $this->view->renderLayout('footer.phtml', './application/views/scripts/'));   //Hien thi footer
            $sGetValueInCookie = Efy_Library::_getCookie("showHideMenu");
            if ($sGetValueInCookie == "" || is_null($sGetValueInCookie) || !isset($sGetValueInCookie)) {
                Efy_Library::_createCookie("showHideMenu", 1);
                $this->view->hideDisplayMeneLeft = 1;
            } else {//Da ton tai Cookie
                if ($sGetValueInCookie != 0) {
                    $this->view->hideDisplayMeneLeft = 1;
                } else {
                    $this->view->hideDisplayMeneLeft = "";
                }
            }
        } else {
            $result = array();

            $result = Efy_Publib_Library::_getAllFileJavaScriptCssArray('', 'efy-js', 'list/jsList.js,list/jquery.uploadify.v2.1.4.min.js,list/swfobject.js,jQuery.equalHeights.js,chosen/chosen.jquery.js,list/list.js,efyxml.js', ',', 'js', $result);
            $result = Efy_Publib_Library::_getAllFileJavaScriptCssArray('', 'efy-style', 'chosen/chosen.css', ',', 'css', $result);
            // $result = Efy_Publib_Library::_getAllFileJavaScriptCssArray('','efy-js','chosen/chosen.jquery.js',',','js',$result);
            $this->view->arrJsCss = Zend_Json::encode($result);
        }
    }

    /**
     * Creater: nghiat
     * Date:
     * Idea: Thuc hien phuong thuc Action hien thi danh sach doi tuong danh muc
     */
    public function indexAction() {
        //Tao cac doi tuong
        $objList = new Listxml_modList();
        $ojbXmlLib = new Efy_Publib_Xml();
        $objFunction = New Efy_Function_RecordFunctions();
        //Tieu de man hinh danh sach
        $this->view->bodyTitle = 'DANH SÁCH ĐỐI TƯỢNG DANH MỤC';
        //Lay danh sach cac THE mo ta tieu tri loc
        $psFilterXmlTagList = "";
        //Lay danh sach cac gia tri tuong ung mo ta tieu tri loc
        $psFilterXmlValueList = "";
        // Lay cac tham param de truyen vao phuong thuc getAllListType : dung cho search
        $iStatus = '';
        $sListTypeName = '';
        $sOwnerCode = $_SESSION['OWNER_CODE'];
        //Lay thong tin loai danh muc de hien thi selectbox "Loai danh muc"
        $arrListType = $objList->getAllListType($iStatus, $sListTypeName, $sOwnerCode);
        //Tao mang mot chieu hien thi selecbox "Loai danh muc"		
        $this->view->arrAllListType = Efy_Library::_createOneDimensionArray($arrListType, 'PK_LISTTYPE', 'C_NAME');
        $psFilterXmlString = $ojbXmlLib->_xmlGenerateXmlDataString($psFilterXmlTagList, $psFilterXmlValueList);
        $iListType = intval($ojbXmlLib->_xmlGetXmlTagValue($psFilterXmlString, 'data_list', 'listtype_type'));
        //$this->view->iIdListType = $iListType;
        //var_dump($arrListType); 
        $iListType = $arrListType[0]['PK_LISTTYPE'];
        //echo htmlspecialchars($psFilterXmlString);
        //Lay thong tin danh muc doi tuong
        $iCurrentPage = 1;
        $iNumberRecordPerPage = 15;
        $arrResult = $objList->getAllList($arrListType, $iListType, $iCurrentPage, $iNumberRecordPerPage, $psFilterXmlString);
        //Lay ten file XML
        $psXmlFileName = $arrResult['xmlFileName'];
        $filexml = substr($psXmlFileName, 1, strlen($psXmlFileName));
        $filexml = 'http://' . $_SERVER['HTTP_HOST'] . $this->_request->getBaseUrl() . $filexml;
        //echo $filexml; die();
        $this->view->filexml = $filexml;
        //Tao form hien thi tieu tri loc	
        $this->view->generateFilterForm = $ojbXmlLib->_xmlGenerateFormfield($psXmlFileName, 'list_of_object/table_struct_of_filter_form/filter_row_list/filter_row', 'list_of_object/filter_formfield_list', $psFilterXmlString, null, true, false);
        $this->view->arrListItem = $objFunction->getAllObjectbyListCode('', 'DM_SO_HS_TREN_TRANG');
        $this->view->iCurrentPage = $iCurrentPage;
        $this->view->iNumberRecordPerPage = $iNumberRecordPerPage;
    }

    public function recordAction() {
        $objList = new Listxml_modList();
        $ojbXmlLib = new Efy_Publib_Xml();

        //Lay danh sach cac THE mo ta tieu tri loc 
        $psFilterXmlTagList = $this->_request->getParam('hdn_filter_xml_tag_list', "");
        $this->view->filterXmlTagList = $psFilterXmlTagList;
        //Lay danh sach cac gia tri tuong ung mo ta tieu tri loc
        $psFilterXmlValueList = $this->_request->getParam('hdn_filter_xml_value_list', "");
        // Lay cac tham param de truyen vao phuong thuc getAllListType : dung cho search
        $iStatus = '';
        $sListTypeName = '';
        $sOwnerCode = $_SESSION['OWNER_CODE'];
        //Lay thong tin loai danh muc de hien thi selectbox "Loai danh muc"
        $arrListType = $objList->getAllListType($iStatus, $sListTypeName, $sOwnerCode);
        //var_dump($arrListType); die();
        $psFilterXmlString = $ojbXmlLib->_xmlGenerateXmlDataString($psFilterXmlTagList, $psFilterXmlValueList);
        $iListType = $this->_request->getParam('listtype_type');
        //echo htmlspecialchars($psFilterXmlString);
        //Lay thong tin quy dinh so row / page
        $piCurrentPage = $this->_request->getParam('hdn_current_page');
        $piNumRowOnPage = $this->_request->getParam('hdn_record_number_page');

        //Lay thong tin danh muc doi tuong
        $arrResult = $objList->getAllList($arrListType, $iListType, $piCurrentPage, $piNumRowOnPage, $psFilterXmlString);
        //die();
        //var_dump($arrResult); die();
        //Mang luu thong tin doi tuong danh muc
        $arrAllList = $arrResult['arrList'];
        //var_dump($arrAllList); die();
        echo Zend_Json::encode($arrAllList);
        $this->_helper->getHelper('viewRenderer')->setNoRender();
        //$this->view->generateHtmlList = $ojbXmlLib->_xmlGenerateList($psXmlFileName,'col',$arrAllList, "C_XML_DATA",'PK_LIST',$this->_request->getParam('list_name',""),false);	
    }

    /**
     * Creater: HUNGVM
     * Date:
     * Idea: Thuc hien phuong thuc Action them moi doi tuong mot loai danh muc
     */
    public function addAction() {
        if (!$this->_request->isXmlHttpRequest()) {
            return $this->_helper->redirector('index');
        }
        // Tieu de cua Form cap  nhat
        $this->view->bodyTitle = 'CẬP NHẬT THÔNG TIN ĐỐI TƯỢNG DANH MỤC';
        //Tao doi tuong XML
        $ojbXmlLib = new Efy_Publib_Xml();
        // Tao doi tuong cho lop tren		
        $objList = new listxml_modList();
        // Thuc hien lay du lieu tu form 		
        if ($this->_request->isPost()) {
            //Lay Id loai danh muc
            $iListType = $this->_request->getParam('hdn_id_listtype', 0);
            $this->view->iIdListType = $iListType;
            $_SESSION['listtypeId'] = $iListType; //Phuc vu menh de where lay so thu tu tiep theo cua doi tuong can them moi
            $arrListTypeResult = $objList->getSingleListType($iListType);
            //var_dump($arrListTypeResult); die();
            $chkAutoGenerateObjectStatus = $arrListTypeResult[0]['C_AUTO_GENERATE_OBJECT_STATUS'];
            $sAutoGenerateObjectCode = "";
            if ($chkAutoGenerateObjectStatus) {
                $sAutoGenerateObjectCode = $arrListTypeResult[0]['C_AUTO_GENERATE_OBJECT_CODE'];
            }
            $this->view->chkAutoGenerateObjectStatus = $chkAutoGenerateObjectStatus;
            $this->view->sAutoGenerateObjectCode = $sAutoGenerateObjectCode;
            //Lay ten file XML
            $psFileName = $arrListTypeResult[0]['C_XML_FILE_NAME'];
            $psFileName = Efy_Init_Config::_setXmlFileUrlPath(1) . "list/".$psFileName;
			//Neu khong ton tai file XML thi doc file XML mac dinh
            if ($psFileName == "" || !is_file($psFileName)) {
                $psFileName = Efy_Init_Config::_setXmlFileUrlPath(1) . "list/quan_tri_doi_tuong_danh_muc.xml";
            }
            $psXmlStr = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
            $arrGetSingleList = array();
            $this->view->generateFormHtml = $ojbXmlLib->_xmlGenerateFormfield($psFileName, 'update_object/table_struct_of_update_form/update_row_list/update_row', 'update_object/update_formfield_list', $psXmlStr, $arrGetSingleList, true, true);
        }
    }

    public function saveAction() {
        if (!$this->_request->isXmlHttpRequest()) {
            return $this->_helper->redirector('index');
        }
        //Tao doi tuong XML
        $ojbXmlLib = new Efy_Publib_Xml();
        //Tao doi tuong Efy_lib
        $ojbEfyLib = new Efy_Library();
        // Tao doi tuong cho lop tren		
        $objList = new listxml_modList();
        // Tao doi tuong Zend_Filter
        $objFilter = new Zend_Filter();

        // Thuc hien lay du lieu tu form 		
        if ($this->_request->isPost()) {
            $psFilterXmlTagList = $this->_request->getParam('hdn_filter_xml_tag_list', "");
            $this->view->filterXmlTagList = $psFilterXmlTagList;
            $psFilterXmlValueList = $this->_request->getParam('hdn_filter_xml_value_list', "");
            $this->view->filterXmlValueList = $psFilterXmlValueList;
            //Lay Id loai danh muc
            $iListType = $this->_request->getParam('hdn_id_listtype', 0);
            $iListId = $this->_request->getParam('hdn_list_id', 0);
            if ($iListId == '')
                $iListId = 0;
            $_SESSION['listtypeId'] = $iListType; //Phuc vu menh de where lay so thu tu tiep theo cua doi tuong can them moi
            $arrListTypeResult = $objList->getSingleListType($iListType);
            $chkAutoGenerateObjectStatus = $arrListTypeResult[0]['C_AUTO_GENERATE_OBJECT_STATUS'];
            $sAutoGenerateObjectCode = "";
            if ($chkAutoGenerateObjectStatus) {
                $sAutoGenerateObjectCode = $arrListTypeResult[0]['C_AUTO_GENERATE_OBJECT_CODE'];
            }
            //Lay ten file XML
            $psFileName = $this->_request->getParam('hdn_xml_file', '');
            //echo $psFileName;
            //Neu khong ton tai file XML thi doc file XML mac dinh
            if ($psFileName == "" || !is_file($psFileName)) {
                $psFileName = Efy_Init_Config::_setXmlFileUrlPath(1) . "list/quan_tri_doi_tuong_danh_muc.xml";
            }

            $psXmlStr = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
            //Lay danh sash THE va GIA TRI tuong ung mo ta chuoi XML, cau truc bien hdn_XmlTagValueList luu TagList|{*^*}|ValueList		
            $psXmlTagValueList = $this->_request->getParam('hdn_XmlTagValueList', '');
            //Tao xau XML luu CSDL
            if ($psXmlTagValueList != "") {
                $arrXmlTagValue = explode("|{*^*}|", $psXmlTagValueList);
                if ($arrXmlTagValue[0] != "" && $arrXmlTagValue[1] != "") {
                    //Danh sach THE
                    $psXmlTagList = $arrXmlTagValue[0];
                    //Danh sach GIA TRI
                    $psXmlValueList = $arrXmlTagValue[1];
                    //Tao xau XML luu CSDL		
                    $psXmlStringInDb = $ojbXmlLib->_xmlGenerateXmlDataString($psXmlTagList, $psXmlValueList);
                }
            }
            //Trang thai cua doi tuong danh muc (HOAT_DONG : hoat dong; NGUNG_HOAT_DONG ; Ngung hoat dong)
            $sStatus = 'NGUNG_HOAT_DONG';
            if ($objFilter->filter($this->_request->getParam('C_STATUS', ''))) {
                $sStatus = 'HOAT_DONG';
            }
            //Neu NSD khong chon thuoc don vi nao thi mac dinh lay ma don vi NSD hien thoi
            $sOwnerCodeList = trim($objFilter->filter($this->_request->getParam('C_OWNER_CODE_LIST', '')));
            if (is_null($sOwnerCodeList)) {
                $sOwnerCodeList = $_SESSION['OWNER_CODE'];
            }
            //Mang luu tham so update in database
            $arrParameter = array(
                'PK_LISTTYPE' => $iListType,
                'PK_LIST' => $iListId,
                'C_CODE' => trim($ojbEfyLib->_replaceBadChar($objFilter->filter($this->_request->getParam('C_CODE', '')))),
                'C_NAME' => trim($ojbEfyLib->_replaceBadChar($objFilter->filter($this->_request->getParam('C_NAME', '')))),
                'C_ORDER' => intval($objFilter->filter($this->_request->getParam('C_ORDER', ''))),
                'C_OWNER_CODE_LIST' => $sOwnerCodeList,
                'C_STATUS' => $sStatus,
                'DELETED_EXIST_FILE_ID_LIST' => '',
                'NEW_FILE_ID_LIST' => '',
                'GET_XML_FILE_NAME' => $psFileName
            );
            $arrResult = "";
            if ($objFilter->filter($this->_request->getParam('C_CODE', '')) != "") {
                $arrResult = $objList->updateList($iListType, $arrParameter, $psXmlStringInDb);
                // Neu add khong thanh cong
                if ($arrResult != null || $arrResult != '') {
                    echo "<script type='text/javascript'>";
                    echo "alert('$arrResult');\n";
                    echo "</script>";
                } else {
                    //Write Xml output file
                    $arrTempList = $objList->createXMLDb($iListType);
                    $listTypeCode = $objList->GetListTypeCode('');
                    //var_dump($arrTempList);exit;
                    $sFilePath = 'xml/list/output/';
                    // Thuc hien Tao file xml
                    $this->createXML($sFilePath, $arrTempList, $listTypeCode);
                }
            }
        }
        $this->_helper->getHelper('viewRenderer')->setNoRender();
    }

    /**
     * Creater: HUNGVM
     * Date: 02/02/2009
     * Idea: Thuc hien Action hieu chinh thong tin doi tuong danh muc
     */
    public function editAction() {
        if (!$this->_request->isXmlHttpRequest()) {
            return $this->_helper->redirector('index');
        }
        // Tieu de cua Form cap  nhat
        $this->view->bodyTitle = 'CẬP NHẬT THÔNG TIN ĐỐI TƯỢNG DANH MỤC';
        //Tao doi tuong XML
        $ojbXmlLib = new Efy_Publib_Xml();
        // Tao doi tuong cho lop tren	
        $objList = new Listxml_modList();

        $psFilterXmlTagList = $this->_request->getParam('hdn_filter_xml_tag_list', "");
        $this->view->filterXmlTagList = $psFilterXmlTagList;
        $psFilterXmlValueList = $this->_request->getParam('hdn_filter_xml_value_list', "");
        $this->view->filterXmlValueList = $psFilterXmlValueList;
        // Thuc hien lay du lieu tu form 		
        if ($this->_request->isPost()) {
            //Lay Id loai danh muc
            $iListType = $this->_request->getParam('hdn_id_listtype', 0);
            $this->view->iIdListType = $iListType;
            $arrListTypeResult = $objList->getSingleListType($iListType);
            $chkAutoGenerateObjectStatus = $arrListTypeResult[0]['C_AUTO_GENERATE_OBJECT_STATUS'];
            $sAutoGenerateObjectCode = "";
            if ($chkAutoGenerateObjectStatus) {
                $sAutoGenerateObjectCode = $arrListTypeResult[0]['C_AUTO_GENERATE_OBJECT_CODE'];
            }
            $this->view->chkAutoGenerateObjectStatus = $chkAutoGenerateObjectStatus;
            $this->view->sAutoGenerateObjectCode = $sAutoGenerateObjectCode;
            //Lay Id loai danh muc
            $iListId = $this->_request->getParam('hdn_list_id', 0);
            $this->view->iIdList = $iListId;
            //Lay ten file XML
            $psFileName = $this->_request->getParam('hdn_xml_file', '');
			$psFileName = $arrListTypeResult[0]['C_XML_FILE_NAME'];
            $psFileName = Efy_Init_Config::_setXmlFileUrlPath(1) . "list/".$psFileName;
            //Neu khong ton tai file XML thi doc file XML mac dinh
            if ($psFileName == "" || !is_file($psFileName)) {
                $psFileName = Efy_Init_Config::_setXmlFileUrlPath(1) . "list/quan_tri_doi_tuong_danh_muc.xml";
            }
            //Lay thong tin danh muc doi tuong
            if ($iListId != 0) {
                $arrGetSingleList = $objList->getSingleList($iListId);
                $psXmlStr = $arrGetSingleList['C_XML_DATA'];
            } else {
                $psXmlStr = '';
                $arrGetSingleList = array();
            }
            //
            if ($psXmlStr != "") {
                $psXmlStr = '<?xml version="1.0" encoding="UTF-8"?>' . $psXmlStr;
            } else {
                $psXmlStr = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
            }

            //Tao xau html mo ta form field cap nhat thong tin va gui ra VIEW hien thi ket qua
            $arrGet1singleInput['0'] = $arrGetSingleList;
            $this->view->generateFormHtml = $ojbXmlLib->_xmlGenerateFormfield($psFileName, 'update_object/table_struct_of_update_form/update_row_list/update_row', 'update_object/update_formfield_list', $psXmlStr, $arrGetSingleList, true, true);
        }
    }

    /**
     * Creater: HUNGVM
     * Date: 02/02/2009
     * Idea: Tao phuong thuc thuc hien xoa doi tuong danh muc
     *
     */
    public function deleteAction() {

        // Tao doi tuong cho lop tren		
        $objList = new Listxml_modList();

        // Thuc hien lay du lieu tu form 		
        if ($this->_request->isPost()) {
            // Lay lai id cua loai danh muc
            $iListTypeId = (int) $this->_request->getParam('hdn_id_listtype', 0);
            $this->view->iIdListType = $iListTypeId;
            //Lay Id loai danh muc
            $iListIdList = $this->_request->getParam('hdn_object_id_list', "");
            if ($iListIdList != "") {
                $psRetError = $objList->deleteList($iListIdList);
                //Write Xml output file
                $arrTempList = $objList->createXMLDb($iListTypeId);
                $listTypeCode = $objList->GetListTypeCode($iListTypeId);
                //var_dump($arrTempList);exit;
                $sFilePath = 'xml/list/output/';
                // Thuc hien Tao file xml
                $this->createXML($sFilePath, $arrTempList, $listTypeCode);
                echo 'OK';
            }
        }
        $this->_helper->getHelper('viewRenderer')->setNoRender();
    }

    /**
     * @see : Ham thuc hien tao file xml 
     * @author: Trinh Thanh Phuong
     * @date: 13/10/2011
     * */
    private function createXML($pFilePath, $arrList, $listTypeCode) {
        if (!empty($arrList)) {
            $strXmlItem = '';
            $strXml = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
            foreach ($arrList as $value) {
                $strXmlItem = '<item><c_status>' . $value['C_STATUS'] . '</c_status><c_code>' . $value['C_CODE'] . '</c_code><c_name>' . $value['C_NAME'] . '</c_name><c_owner_code>' . $value['C_OWNERCODE'] . '</c_owner_code>';
                if ($value['C_XML_DATA'] != '') {
                    $xmlData = '<?xml version="1.0" encoding="UTF-8"?>' . $value['C_XML_DATA'];
                    $objXmlData = new Zend_Config_Xml($xmlData, 'data_list');
                    $arrXmlData = $objXmlData->toArray();
                    $arrKey = array_keys($arrXmlData);
                    foreach ($arrKey As $valueKey) {
                        $strXmlItem .= '<' . $valueKey . '>' . $arrXmlData[$valueKey] . '</' . $valueKey . '>';
                    }
                }
                $strXmlItem .= '</item>';
                $strXml .= $strXmlItem;
            }
            $strXml .= '</data_list></root>';
            Efy_Library::_writeFile($pFilePath . $arrList[0]['LISTTYPE_CODE'] . '.xml', $strXml);
        } else {
            if (file_exists($pFilePath . $listTypeCode . '.xml'))
                unlink($pFilePath . $listTypeCode . '.xml');
        }
    }

    /**
     * Creater: HUNGVM
     * Date:27/12/2011
     * Idea: Xử lý import dữ liệu vào một loại danh mục
     */
    public function importAction() {
        // Tieu de cua Form cap  nhat
        $this->view->bodyTitle = 'IMPORT DỮ LIỆU';
        //Tao doi tuong XML
        $ojbXmlLib = new Efy_Publib_Xml();
        //Tao doi tuong Efy_lib
        $ojbEfyLib = new Efy_Library();
        // Tao doi tuong cho lop tren		
        $objList = new listxml_modList();
        // Tao doi tuong Zend_Filter
        $objFilter = new Zend_Filter();
        // Thuc hien lay du lieu tu form 		
        if ($this->_request->isPost()) {
            // Lay toan bo tham so truyen tu form			
            $arrInput = $this->_request->getParams();
            $psFilterXmlTagList = $this->_request->getParam('hdn_filter_xml_tag_list', "");
            $this->view->filterXmlTagList = $psFilterXmlTagList;
            $psFilterXmlValueList = $this->_request->getParam('hdn_filter_xml_value_list', "");
            $this->view->filterXmlValueList = $psFilterXmlValueList;
            //Lay thong tin trang hien thoi
            $piCurrentPage = $this->_request->getParam('hdn_current_page', 0);
            $this->view->currentPage = $piCurrentPage;
            //Lay thong tin quy dinh so row / page
            $piNumRowOnPage = $this->_request->getParam('hdn_record_number_page', 0);
            $this->view->numRowOnPage = $piNumRowOnPage;
            //Lay Id loai danh muc
            $iListType = $this->_request->getParam('hdn_id_listtype', 0);
            $this->view->iIdListType = $iListType;
            $_SESSION['listtypeId'] = $iListType; //Phuc vu menh de where lay so thu tu tiep theo cua doi tuong can them moi	
            //Lay thong tin loai danh muc de hien thi selectbox "Loai danh muc"			
            $arrListType = $objList->getAllListType("", "", $_SESSION['OWNER_CODE']);
            $sListTypeName = "";
            for ($index = 0; $index < sizeof($arrListType); $index++) {
                if ($arrListType[$index]['PK_LISTTYPE'] == $iListType) {
                    $sListTypeName = $arrListType[$index]['C_NAME'];
                    break;
                }
            }
            $this->view->sListTypeName = $sListTypeName;
            //Lay ten file XML
            $psFileName = $this->_request->getParam('hdn_xml_file', '');
            //echo $psFileName;
            //Neu khong ton tai file XML thi doc file XML mac dinh
            if ($psFileName == "" || !is_file($psFileName)) {
                $psFileName = Efy_Init_Config::_setXmlFileUrlPath(1) . "list/quan_tri_doi_tuong_danh_muc.xml";
            }
            //Lay danh sash THE va GIA TRI tuong ung mo ta chuoi XML, cau truc bien hdn_XmlTagValueList luu TagList|{*^*}|ValueList		
            $psXmlTagValueList = $this->_request->getParam('hdn_XmlTagValueList', '');
            //Tao xau XML luu CSDL
            if ($psXmlTagValueList != "") {
                $arrXmlTagValue = explode("|{*^*}|", $psXmlTagValueList);
                if ($arrXmlTagValue[0] != "" && $arrXmlTagValue[1] != "") {
                    //Danh sach THE
                    $psXmlTagList = $arrXmlTagValue[0];
                    //Danh sach GIA TRI
                    $psXmlValueList = $arrXmlTagValue[1];
                    //Tao xau XML luu CSDL					
                    $psXmlStringInDb = $ojbXmlLib->_xmlGenerateXmlDataString($psXmlTagList, $psXmlValueList);
                }
            }
            // Thuc hien tao mot mang de day vao view
            $this->view->arrInput = $arrInput;

            if ($objFilter->filter($arrInput['C_CODE']) != "") {
                $arrResult = $objList->updateList($iListType, $arrParameter, $psXmlStringInDb);
                // Neu add khong thanh cong			
                if ($arrResult != null || $arrResult != '') {
                    echo "<script type='text/javascript'>";
                    echo "alert('$arrResult');\n";
                    echo "</script>";
                } else {
                    //Luu gia tri												
                    $arrParaSet = array("hdn_id_listtype" => $iListType, "hdn_xml_file" => $psFileName, "sel_page" => $piCurrentPage, "cbo_nuber_record_page" => $piNumRowOnPage, "hdn_filter_xml_tag_list" => $psFilterXmlTagList, "hdn_filter_xml_value_list" => $psFilterXmlValueList);
                    //var_dump($arrParaSet); exit;
                    $_SESSION['seArrParameter'] = $arrParaSet;
                    $this->_request->setParams($arrParaSet);
                    //Write Xml output file
                    $arrTempList = $objList->createXMLDb($iListType);
                    $listTypeCode = $objList->GetListTypeCode($iListTypeId);
                    //var_dump($arrTempList);exit;
                    $sFilePath = 'xml/list/output/';
                    // Thuc hien Tao file xml
                    $this->createXML($sFilePath, $arrTempList, $listTypeCode);
                    //Tro ve trang index						
                    $this->_redirect('listxml/list/index/');
                }
            }
        }
    }

}

?>